﻿/*
 * ============ [ 废土 ] ============
 *
 * [ 维护者 ]  argoran@gmail.com
 * [  状态  ]  原型
 *
 * ============ [ 注释 ] ============
 *
 * 处理create指令的类
 *
 * ==================================
 */

using System;

using LastLandClient.Data;

using Up2Link.SegString;
using Up2Link.Util;

namespace LastLandClient.Core.CmdInterpreter
{
    public class CCmdCreateCharacter : ICommandInterpreter
    {
        public void ExecuteCommand(string _cmd, string _args)
        {
            if (_args == null && CData.clientConnected)
            {
                CMessageSS createMsg = new CMessageSS(CConst.CLIENT_MESSAGE_CREATE_NORMAL, 0, CMessageSS.ENCODING_UTF32, "");
                CData.client.Send(createMsg);
            }
            else if (_args != null && CData.clientConnected)
            {
                String[] args = _args.Split(CConst.DELIMITER_ARGUMENT);
                if (args.Length == 1)
                {
                    String arg = args[0].ToLowerInvariant().Trim();
                    Int32 msgCode = 0;
                    switch (arg)
                    {
                        case "leader":
                            msgCode = CConst.CLIENT_MESSAGE_CREATE_LEADER;
                            break;
                        default:
                            break;
                    }

                    if (msgCode != 0)
                    {
                        CMessageSS createMsg = new CMessageSS(msgCode, 0, CMessageSS.ENCODING_UTF32, "");
                        CData.client.Send(createMsg);
                    }
                    else
                    {
                        CData.console.SendOutput("参数" + arg + "无效");
                        CData.console.SendOutput("create:leader");
                    }
                }
                else if (args.Length != 1)
                {
                    CData.console.SendOutput("create指令接受至多一个参数");
                }
                else
                {
                    CData.console.SendOutput("无效的指令");
                }
            }
            else if (!CData.clientConnected)
            {
                CData.console.SendOutput("玩家尚未连接服务器");
            }
            else
            {
                CData.console.SendOutput("无效的指令");
            }
        }
    }
}